#include "stdafx.h"
#include "vDxDisplay.h"

namespace vview
{

IMPLEMENT_RUNTIMEINFO(CDxDisplay, CVObject)

bool CDxDisplay::SetOptions( DxOptions opt, DWORD value )
{
	return false;
}

int CDxDisplay::GetDisplayModeCount()
{
	InitDisplayMode();
	if (!m_DisplayModeInited)
		return 0;
	else 
		return m_DisplayModeVector.size();
}

bool CDxDisplay::GetDisplayMode( int nIdx, DxDisplayMode& mode )
{
	InitDisplayMode();
	if (m_DisplayModeInited && (0 <= nIdx) && (nIdx < (int)m_DisplayModeVector.size()))
	{
		mode = m_DisplayModeVector[nIdx];
		return true;
	}	
	return false;
}

vview::DxFormat CDxDisplay::GetCurDisplayFormat()
{
	DxDisplayMode mode;
	if (GetCurDisplayMode(mode))
		return mode.Format;
	else
		return DxFmt_Unknown;
}

vview::DxFormat CDxDisplay::GetDisplayFormat( int nIdx )
{
	DxDisplayMode mode;
	if (!GetDisplayMode(nIdx, mode))
		return DxFmt_Unknown;
	else
		return mode.Format;
}

bool CDxDisplay::CheckDisplayMode( DxDisplayMode& mode )
{
	InitDisplayMode();
	if (m_DisplayModeInited)
	{
		DisplayModeVector::iterator itr = m_DisplayModeVector.begin();
		DxDisplayMode curMode;
		while (itr != m_DisplayModeVector.end())
		{
			curMode = *itr;
			if ((curMode.Format == mode.Format) &&
				(curMode.Width == mode.Width) && 
				(curMode.Height == mode.Height) &&
				((mode.RefreshRate == 0) || (curMode.RefreshRate == mode.RefreshRate)))
				return true;
			++itr;
		}
	}
	return false;
}

bool CDxDisplay::CheckDisplayFormat( DxFormat fmt )
{
	InitDisplayMode();
	if (m_DisplayModeInited)
	{
		DisplayModeVector::iterator itr = m_DisplayModeVector.begin();
		DxDisplayMode curMode;
		while (itr != m_DisplayModeVector.end())
		{
			curMode = *itr;
			if (curMode.Format == fmt) 
				return true;
			++itr;
		}
	}
	return false;
}

bool CDxDisplay::SetWindow( HWND hwnd )
{
	if (m_hWnd != hwnd)
	{
		m_hWnd = hwnd;
		return Reset();
	}
	return true;
}

bool CDxDisplay::SetSize( int nWidth, int nHeight )
{
	if ((m_Width != nWidth) && (m_Height != nHeight))
	{
		m_Width = nWidth;
		m_Height = nHeight;
		return Reset();
	}
	return true;
}

bool CDxDisplay::SetBitDepth( DxBitDepth bitDepth )
{
	if (m_BitDepth != bitDepth)
	{
		m_BitDepth = bitDepth;
		return Reset();
	}
	return true;
}

bool CDxDisplay::SetFullScreen( bool bFullScreen )
{
	if (m_bFullScreen != bFullScreen)
	{
		m_bFullScreen = bFullScreen;
		return Reset();
	}
	return true;
}

DWORD CDxDisplay::GetOpeionts( DxOptions opt )
{
	return 0;
}

void CDxDisplay::SetBkColor( DxColor color )
{
	m_BkColor = color;
}
}